import axios from "axios";

const UPLOAD_USER_IMAGE_API = "/api/uploadUserImage"

const uploadUserImageRequest = async (
    coverImage: Blob | null = null,
    headImage: Blob | null = null
) => {
    try {
        const formData = new FormData();
        if (coverImage) {
            formData.append('coverImage', coverImage);
        }
        if (headImage) {
            formData.append('headImage', headImage);
        }

        return await axios.post(UPLOAD_USER_IMAGE_API, formData, {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        });
    }catch (e){
        return {
            data: {
                message: e,
                success: false
            }
        }
    }
}

const UPLOAD_USER_INFO_API = "/api/uploadUserInfo"

const uploadUserInfoRequest = async (userInfo: { nickname: string; gender: number; intro: string }) => {
    return await axios.post(UPLOAD_USER_INFO_API, userInfo);
}

const REGISTRY_USER_API = "/api/registryUser"

const registryUserRequest = async (registryData: {}) => {
    return await axios.post(REGISTRY_USER_API, registryData);
}

export {
    uploadUserImageRequest,
    uploadUserInfoRequest,
    registryUserRequest
}
